﻿namespace Nomo.UnityCoreModule.Waiters
{
    /// <summary>
    /// 时间等待器。
    /// </summary>
    public abstract class TimeWaiter : Waiter
    {
        private protected readonly float WaitTime;
        private protected          float CurrentTime;

        internal float InternalGetWaitTime    => WaitTime;
        internal float InternalGetCurrentTime => CurrentTime;

        internal TimeWaiter(float waitTime)
        {
            if (float.IsNaN(waitTime))
            {
                throw new System.ArgumentOutOfRangeException(nameof(waitTime));
            }

            WaitTime    = UnityEngine.Mathf.Max(waitTime, default);
            CurrentTime = default;
        }

        /// <inheritdoc />
        public sealed override bool MoveNext()
        {
            return !Completed && base.MoveNext();
        }

        /// <inheritdoc />
        public override void Reset()
        {
            base.Reset();
            CurrentTime = default;
        }
    }
}
